home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 300_01 / mat_v2d.h < prev    next >
C/C++ Source or Header  |  1989-12-28  |  10KB  |  227 lines

  1. /*   HEADER:   CUG300;
  2.       TITLE:   Matrix library;
  3.        DATE:   4/09/1989;
  4. DESCRIPTION:   "Series of macros and functions which accomodate dynamic
  5.                declaration of arrays on heap. Functions provide
  6.                declaration, access, and various operations on both float
  7.                and string arrays. Float array operations are row and
  8.                column sums, moving averages, cumulative totals,
  9.                determinants, cofactor, inverse, transpose, solution,
  10.                etc. Token arrays may be input and output from commented
  11.                textfiles. Other functions transfer token and float
  12.                elements between the two types of arrays. Maximum array
  13.                size is 64k.";
  14.     VERSION:   2.04;
  15.    KEYWORDS:   heap,array,textfile,i/o,error,float,token,allocation,matrix,
  16.                mathematics;
  17.    FILENAME:   MAT_V2D.H;
  18.      SYSTEM:   MS-DOS;
  19.     AUTHORS:   John J. Hughes;
  20.   COMPILERS:   Turbo C;
  21. */
  22. /*
  23. Credits: The following routines were based on functions and macros
  24. developed at the University of Maryland, Computer Science Dept. (July
  25. 28, 1983 by Fred Blonder) and placed in the public domain:
  26.  
  27. mfcof      mfdet   mfcpy   mfdump     mfread     mftrnsp
  28. mfmlt      mfslv   mfinv
  29.  
  30. Remaining functions and macros were developed by:
  31.  
  32.                            John J. Hughes III
  33.                            928 Brantley Drive
  34.                            Knoxville, TN 37923
  35.                             (615)    693-5695
  36.  
  37. Users are encouraged to register at the above address and to advise the
  38. author of any errors or omissions found in the source code.
  39.  
  40. Since the source code is available for a nominal fee, users must bear
  41. full responsibility for verifying the code's correctness and adequacy
  42. for any particular application.  The author disclaims any responsibility
  43. for errors and omissions in the source code and for any damages
  44. resulting from those errors and omissions.
  45.  
  46. This header file and any object or executable images (i.e. *.obj, *.exe,
  47. *.com or *.lib files) compiled from the source code for functions
  48. prototyped in this header file may be releasesed to the public domain.
  49. The C language source code for the functions prototyped in this header
  50. file is copyrighted. */
  51.  
  52. #ifndef __STDLIB
  53. #include <STDLIB.H>
  54. #endif
  55.  
  56. #ifndef __STDIO_DEF_
  57. #include <STDIO.H>
  58. #endif
  59.  
  60. #ifndef FA_ARCH
  61. #include <DOS.H>
  62. #endif
  63.  
  64. /*          CONSTANT DEFINITIONS
  65. */
  66. #define YES       1
  67. #define NO        0
  68. #define STARTED   1
  69. #define ENDED     0
  70. #define M_NULL    0
  71. #define DCLVCT    1
  72. #define VCT       0
  73. #define NRW       66
  74. #define NRM       80
  75. #define WD        128
  76. #define FTOK      16
  77. #define DP        3
  78. #define TOK       24
  79. #define MAXFLDS   32
  80.  
  81. /*          STRUCTURE TYPE DEFNITIONS
  82. */
  83. struct fmat {  unsigned int n_rows,n_cols,atrib1,atrib2; float *f; };
  84. struct tmat {  unsigned int n_rows,n_cols,tok_sz,n_recs,*n_toks; char *t;  };
  85.  
  86. /*          FUNCTIONS PROTOTYPES
  87.  
  88.             General Purpose Array Functions
  89. */
  90. void     error    (unsigned int flag, unsigned int errno, unsigned int arg1,
  91.                             unsigned int arg2);
  92. void     msc      (FILE *FN,char *text);
  93. void     msl      (FILE *FN,char *text);
  94. void     msr      (FILE *FN,char *text);
  95. void     mst      (FILE *FN,char *label,char *variable);
  96. void     msv      (FILE *FN,char *label,float value);
  97.  
  98. /*          Floating Point Array Functions
  99. */
  100. void     mfcnt    (char filename[],unsigned int *rows,unsigned int *cols);
  101. float    mfcof    (struct fmat *mtx,unsigned int i,unsigned int j);
  102. void     mfcpy    (struct fmat *copy_mtx,struct fmat *mtx);
  103. void     mfcumc   (struct fmat *mtx,unsigned int col,unsigned int bgn_row,
  104.                             unsigned int end_row,unsigned int result_col);
  105. void     mfcumr   (struct fmat *mtx,unsigned int row,unsigned int bgn_col,
  106.                             unsigned int end_col,unsigned int result_row);
  107. float    mfdet    (struct fmat *mtx);
  108. void     mfdump   (struct fmat *mtx);
  109. void     mfget    (char filename[],struct fmat *mtx);
  110. void     mfinv    (struct fmat *inv_mat,struct fmat *mtx);
  111. void     mfmlt    (struct fmat *result_mat,struct fmat *mat1,
  112.                         struct fmat *mat2);
  113. void     mfmvac   (struct fmat *mtx,unsigned int nopds,unsigned int col,
  114.                                 unsigned int bgn_row,unsigned int end_row,
  115.                                 unsigned int result_col);
  116. void     mfmvar   (struct fmat *mtx,unsigned int nopds,unsigned int row,
  117.                                 unsigned int bgn_col,unsigned int end_col,
  118.                                 unsigned int result_row);
  119. void     mfpgput  (struct fmat *mtx,char filename[],unsigned int ChPrLn,
  120.                                 unsigned int FldPrLn,unsigned int DcP);
  121. void     mfput    (FILE *FN,struct fmat *mtx,char hdr_lst[],char sel_lst[],
  122.                                 unsigned int ChPrLn,unsigned int FldPrLn,
  123.                                 unsigned int DcP);
  124. void     mfread   (struct fmat *mtx,char filename[]);
  125. void     mfslv    (struct fmat *solu_mat,struct fmat *coef_mat,
  126.                         struct fmat *const_mat);
  127. void     mfstore  (char filename[], struct fmat *mtx);
  128. float    mfsumc   (struct fmat *mtx,unsigned int row,unsigned int bgn_col,
  129.                                 unsigned int end_col);
  130. float    mfsumr   (struct fmat *mtx,unsigned int col,unsigned int bgn_row,
  131.                                 unsigned int end_row);
  132. void     mftrnsp  (struct fmat *trns_mat,struct fmat *mtx);
  133.  
  134. /*          Text Array Functions
  135. */
  136. void     mtapnd   (struct tmat *apnd_mat, struct tmat *src_mat,unsigned int src_row);
  137. void     mtcnt    (char filename[], unsigned int *rows,
  138.                             unsigned int *maxtoks,unsigned int *maxtoksz);
  139. void     mtcpy    (struct tmat *source, struct tmat *destin);
  140. void     mtdump   (struct tmat *matrix);
  141. void     mtget    (char filename[],struct tmat *mtx);
  142. void     mtput    (FILE *FN,struct tmat *mtx,char hdlst[], char sel_lst[],
  143.                         unsigned int ChPerLn,unsigned int FldPrLn);
  144. void     mtread   (char filename[],struct tmat *mtx);
  145. void     mtstore  (char filename[],struct tmat *mtx);
  146.  
  147. /*          Text Array Access Functions
  148. */
  149. void     ft       (struct tmat *mtx,unsigned int line,unsigned int token,
  150.                                 float value,unsigned int ChPrLn,unsigned int FldPrLn,
  151.                                 unsigned int DcPlc);
  152. void     it       (struct tmat *mtx,unsigned int line,unsigned int token,
  153.                                 unsigned int value,unsigned int ChPrLn,
  154.                                 unsigned int FldPrLn);
  155. float    tf       (struct tmat *mtx,unsigned int line,unsigned int token,
  156.                                 unsigned int notoks);
  157. unsigned int         ti           (struct tmat *mtx,unsigned int line,unsigned int token,
  158.                                 unsigned int notoks);
  159. void     tmtofm   (struct fmat *mtxf,struct tmat *mtxt);
  160. char    *ts       (struct tmat *mtx,unsigned int line,unsigned int token,
  161.                                 unsigned int notoks);
  162. void     tt       (struct tmat *mtx,unsigned int line,unsigned int token,
  163.                                 char *buffer,unsigned int ChPrLn,
  164.                                 unsigned int FldPrLn);
  165.  
  166. /*          GENERAL PURPOSE MACROS
  167. */
  168. #define  flcreat(filename,FN) if((FN=fopen(filename,"w"))==0)\
  169.          error(NO,23,0,0);{struct date today;getdate(&today);\
  170.          fprintf (FN,"{\n%s  %d/%d/%d\n",\
  171.          filename,today.da_mon,today.da_day,today.da_year);}\
  172.          fprintf (FN,"}\n")
  173. #define  no_cols(mx)    ((mx)->n_cols)
  174. #define  no_recs(mx)    ((mx)->n_recs)
  175. #define  no_rows(mx)    ((mx)->n_rows)
  176. #define  no_toks(mx,rw) ((mx)->n_toks[(unsigned)(rw)])
  177. #define  token_sz(mx)   ((mx)->tok_sz)
  178.  
  179.  
  180. #define  all(m,rw,cl)   for (rw=0; rw<((m)->n_rows); rw++)\
  181.                         for (cl=0; cl<((m)->n_cols); cl++)
  182. #define  cols(m,cl)     for (cl=0; cl<((m)->n_cols); cl++)
  183. #define  rows(m,rw)     for (rw=0; rw<((m)->n_rows); rw++)
  184. #define  trecs(mx,rw)   for (rw=0; rw<((m)->n_recs); rw++)
  185.  
  186. /*          MATRIX ACCESS MACROS
  187. */
  188. #define  f(mx,rw,cl)    ((mx)->f[(unsigned)(rw)*(mx)->n_cols+(cl)])
  189. #define  t(mx,rw,cl)    (char *)(&(mx)->t[(unsigned)(rw)*((mx)->n_cols)*\
  190.                                 (mx)->tok_sz+(cl)*(mx)->tok_sz])
  191.  
  192. /*          MATRIX ALLOCATION & POINTER MACROS
  193. */
  194. #define fck(mx,rw,cl)   if ( (rw)>=(mx)->n_rows || (cl)>=(mx)->n_cols)\
  195.                         error (YES,19,(rw),(cl));
  196. #define fdim(mx,rw,cl)  { unsigned int nnni;  if\
  197.             ( (int) (((mx)=(struct